import { reactive, ref } from 'vue';
import * as api from '@/api/pack/pack';

export default function () {
  /**
   * @method 主页table表格的标题
   */
  const columns: any = reactive([
    {
      title: '资源名称',
      dataIndex: 'name',
      ellipsis: true,
      tooltip: true,
      slotName: 'Splicing'
    },
    {
      title: '描述',
      dataIndex: 'name',
      ellipsis: true,
      tooltip: true,
      slotName: 'Splicing'
    },
    {
      title: '资产编号',
      dataIndex: 'code',
      ellipsis: true,
      tooltip: true
    },
    {
      title: '资产版本',
      dataIndex: 'version',
      ellipsis: true,
      tooltip: true,
      slotName: 'version'
    },
    {
      title: '录入人',
      dataIndex: 'create_user_name',
      ellipsis: true,
      tooltip: true
    },
    {
      title: '登记状态',
      dataIndex: 'status',
      slotName: 'status',
      ellipsis: true,
      tooltip: true
    },
    {
      title: '录入时间',
      dataIndex: 'create_time',
      ellipsis: true,
      tooltip: true
    },
    {
      title: '更新时间',
      dataIndex: 'update_time',
      ellipsis: true,
      tooltip: true
    },
    {
      title: '操作',
      slotName: 'handle',
      align: 'right',
      ellipsis: true,
      tooltip: true,
      fixed: 'right',
      width: 250
    }
  ]);

  /**
   * @method 主页table表格的数据
   */

  const tableData = ref([]);
  /**
   * @method 获取主页标题数据
   */
  const titleData = ref([]);
  const getTitle = async () => {
    const res = await api.getTitle();
    titleData.value = res.data;
  };
  /**
   * @method 获取资产打包列表
   */
  const AssetList = ref({
    total: 0,
    page: 1,
    page_size: 10,
    registration_status: '全部',
    key: ''
  });
  const handleSizeChange = (e) => {
    AssetList.value.page_size = e;
    getList();
  };
  const handleCurrentChange = (e) => {
    AssetList.value.page = e;
    getList();
  };
  const getList = async () => {
    const obj = {
      ...AssetList.value
    };
    if (obj.registration_status === '全部') {
      obj.registration_status = '';
    }
    const res = await api.getList(obj);
    console.log(res);
    tableData.value = res.data;
    AssetList.value.total = res.total;
  };
  /**
   * @method  搜索
   */
  const handleSearch = () => {
    getList();
  };
  return {
    columns,
    tableData,
    getList,
    AssetList,
    handleSearch,
    getTitle,
    titleData,
    handleSizeChange,
    handleCurrentChange
  };
}
